package dao.oc_user_name;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import entitybean.oc_user_name.EntityBeanOc_User_Name;

public class DaoImpl_Oc_User_Name  extends HibernateDaoSupport implements Dao_Oc_User_Name{
	public void Insert_Oc_User_Name(EntityBeanOc_User_Name e)
	{
		this.getHibernateTemplate().save(e);
	}
	public void Update_Oc_User_Name(EntityBeanOc_User_Name e)
	{
		this.getHibernateTemplate().update(e);
	}
	public void Delete_Oc_User_Name(EntityBeanOc_User_Name e)
	{
		this.getHibernateTemplate().delete(e);
	}
	@SuppressWarnings("unchecked")
	public EntityBeanOc_User_Name Find_EntityBeanOc_User_Name_By_ID(Integer id)
	{
		EntityBeanOc_User_Name e=new EntityBeanOc_User_Name();
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where id="+id);
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
		
	}
	@SuppressWarnings("unchecked")
	public EntityBeanOc_User_Name Find_EntityBeanOc_User_Name(String username,String password)
	{
		EntityBeanOc_User_Name e=new EntityBeanOc_User_Name();
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where isactive='ON' and username='"+username+"' and password='"+password+"'");
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
	}
	@SuppressWarnings("unchecked")
	public EntityBeanOc_User_Name Find_EntityBeanOc_User_Name_Admin(String username,String password)
	{
		EntityBeanOc_User_Name e=new EntityBeanOc_User_Name();
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where isactive='ON' and power<>'OFF' and username='"+username+"' and password='"+password+"'");
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
		
		
		
	}
	@SuppressWarnings("unchecked")
	public void Delete_Oc_User_Name(String id)
	{
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and id in("+id+")");	
		for(int i=0;i<list.size();i++)
		{
			EntityBeanOc_User_Name e=list.get(i);
			e.setDel("ON");
			this.getHibernateTemplate().update(e);
			
		}
	}
	@SuppressWarnings("unchecked")
	public void Update_Forbid_Oc_User_Name(String id)
	{
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and id in("+id+")");	
		for(int i=0;i<list.size();i++)
		{
			EntityBeanOc_User_Name e=list.get(i);
			e.setIsactive("OFF");
			this.getHibernateTemplate().update(e);
			
		}
	}
	@SuppressWarnings("unchecked")
	public void Update_Active_Oc_User_Name(String id)
	{
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and id in("+id+")");	
		for(int i=0;i<list.size();i++)
		{
			EntityBeanOc_User_Name e=list.get(i);
			e.setIsactive("ON");
			this.getHibernateTemplate().update(e);
			
		}
	}
	public EntityBeanOc_User_Name Find_EntityBeanOc_By_Email(String email) {
		EntityBeanOc_User_Name e=new EntityBeanOc_User_Name();
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where  email='"+email+"' ");
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
	}
	public List<EntityBeanOc_User_Name> Find_EntityBeanOcByMail(String email) {
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and email='"+email+"'");	
		return list	;
	}
	public List<EntityBeanOc_User_Name> Find_EntityBeanOcByName(String username) {
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and username='"+username+"'");	
		return list	;
	}
	public List<EntityBeanOc_User_Name> Find_EntityBeanOcByMail(
			String email, String id) {
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and email='"+email+"' and id !='"+id+"'");	
		return list	;
	}
	public List<EntityBeanOc_User_Name> Find_EntityBeanOcByName(
			String username, String id) {
		List<EntityBeanOc_User_Name> list=this.getHibernateTemplate().find("from EntityBeanOc_User_Name where del='OFF' and username='"+username+"' and id !='"+id+"'");	
		return list	;
	}

	
}
